/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package game.platformer.combat;

import com.badlogic.gdx.math.Vector2;
import game.platformer.combat.Bullet;
import java.util.LinkedList;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

/**
 *
 * @author cow
 */
public class BulletPool {
    LinkedList<Bullet> BulletPool;
    Scene MapScene;
    TextureRegion bulletTR;
    PhysicsWorld mPhysicsWorld;
    
    public BulletPool(Scene scn, TextureRegion inptBulletTR, PhysicsWorld inptPhysicsWorld){
        this.MapScene=scn;
        this.bulletTR=inptBulletTR;
        this.mPhysicsWorld=inptPhysicsWorld;
        this.BulletPool = new LinkedList<Bullet>();
    }
    
    public Bullet getBullet(){
        //If we have no bullets in our pool, make a new one
        if(BulletPool.isEmpty()){
            Bullet tempBullet = new Bullet(this.MapScene, this.bulletTR,
                    this.mPhysicsWorld, 0, 0);
            return tempBullet;
        }else{//Else return one from the pool
            return BulletPool.removeLast();
        }
    }
    
    public void launch(float posX, float posY, Vector2 velocity){
        Bullet tempBullet;
        tempBullet = getBullet();
        
        //tempBullet.enable();
        tempBullet.setPosition(posX, posY);
        tempBullet.setVelocity(velocity);
    }
    
    public void recycle(Bullet inptBullet){
        inptBullet.disable();
        BulletPool.add(inptBullet);
    }
}
